#ifndef FIELD_H_
#define FIELD_H_

#include "Common.h"
#include "String.h"
#include "StringConverter.h"

#include <map>

class Field
{
public:
	Field():mValue(""){}
	Field(const String & value)
	{
		mValue = value;
	}

	Field(const int & value)
	{
		mValue = StringConverter::toString(value);
	}
	Field(const uint32 & value)
	{
		mValue = StringConverter::toString(value);
	}
	Field(const float & value)
	{
		mValue = StringConverter::toString(value);
	}

	Field(const double & value)
	{
		mValue = StringConverter::toString(value);
	}

	Field(const int64 & value)
	{
		mValue = StringConverter::toString(value);
	}

	Field(const uint64 & value)
	{
		mValue = StringConverter::toString(value);
	}

	Field(const bool & value)
	{
		mValue = StringConverter::toString(value);
	}
	Field(const Field & value)
	{
		mValue = value.GetValue();
	}

	WGSERVER_INLINE void SetValue(const char* value)
	{       
                if(value)
                   mValue = value; 
                else
                   mValue = "";
        }
	WGSERVER_INLINE void SetValue(const String &  value) { mValue = value; }
	const String & GetValue() const { return mValue; } 
	WGSERVER_INLINE const char *GetString() { return mValue.c_str(); }


	Field & operator=(const Field & val)
	{
		mValue = val.GetValue();
		return *this;
	}
	Field & operator=(const uint32 &value)
	{
		mValue = StringConverter::toString(value);
		return *this;
	}

	Field & operator=(const int32 &value)
	{
		mValue = StringConverter::toString(value);
		return *this;
	}


	Field & operator=(const float &value)
	{
		mValue = StringConverter::toString(value);
		return *this;
	}

	Field & operator=(const double &value)
	{
		mValue = StringConverter::toString(value);
		return *this;
	}

	Field & operator=(const int64 &value)
	{
		mValue = StringConverter::toString(value);
		return *this;
	}

	Field & operator=(const uint64 &value)
	{
		mValue = StringConverter::toString(value);
		return *this;
	}

	Field & operator=(const bool &value)
	{
		mValue = StringConverter::toString(value);
		return *this;
	}

	WGSERVER_INLINE float GetFloat() { return mValue.size() ? StringConverter::parseReal(mValue) : 0; }
	WGSERVER_INLINE bool GetBool() { return mValue.size() ? StringConverter::parseBool(mValue) > 0 : false; }
	WGSERVER_INLINE uint8 GetUInt8() { return mValue.size() ? (uint8) StringConverter::parseUnsignedInt(mValue) : 0; }
	WGSERVER_INLINE int8 GetInt8() { return mValue.size() ? (int8) StringConverter::parseInt(mValue) : 0; }
	WGSERVER_INLINE uint16 GetUInt16() { return mValue.size() ? (uint16) StringConverter::parseUnsignedInt(mValue) : 0; }
	WGSERVER_INLINE int16 GetInt16() { return mValue.size() ? (int16) StringConverter::parseInt(mValue) : 0; }
	WGSERVER_INLINE uint32 GetUInt32() { return mValue.size() ? StringConverter::parseUnsignedInt(mValue) : 0; }
	WGSERVER_INLINE int32 GetInt32() { return mValue.size() ? StringConverter::parseInt(mValue) : 0; }
	WGSERVER_INLINE	uint64 GetUInt64() { return mValue.size() ?  StringConverter::parseUnsigned64(mValue):0;	}
	WGSERVER_INLINE	int64 GetInt64() { return mValue.size() ?  StringConverter::parseInt64(mValue):0;	}
	WGSERVER_INLINE	double GetDouble() { return mValue.size() ?  StringConverter::parseDouble(mValue):0;	}

private:
	String	mValue;
};

typedef std::map<String,Field>  Fields;
typedef std::vector<Fields>	FieldRows;

#endif
